import java.util.HashSet;
import java.util.Iterator;

public class work1 {
    public int[] singleNumber(int[] nums) {
        HashSet<Integer>set=new HashSet<>();
        for (int i = 0; i < nums.length ; i++) {
            if(set.contains(nums[i]))set.remove(nums[i]);
            else set.add(nums[i]);
        }
        int []arr=new int[set.size()];
        int i=0;
        Iterator<Integer> iterator=set.iterator();
        for (Iterator<Integer> it = iterator; it.hasNext(); ) {
            int temp = it.next();
            arr[i]=temp;
            i++;
        }
        return arr;
    }
    public int[] singleNumber2(int[] nums) {
        int sum=0;
        for(int temp:nums){
            sum^=temp;
        }
        int ret1=0,ret2=0;
        for(int temp:nums){
            sum^=temp;
            if(sum==0){
                ret2=temp;
            }else{
                ret1^=temp;
            }
        }
        return new int[]{ret1,ret2};
    }
}
